package com.endpoint.book.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @Project: endpoint
 * @Name: RabbitConfig
 * @Author: Jack_Li
 * @Date: 2024/7/8 17:16
 */
@Configuration
public class RabbitConfig {

    private static final String ADD_BOOK_VISIT_EXCHANGE = "ADD-BOOK-VISIT-EXCHANGE";

    private static final String UPDATE_ES_QUEUE = "UPDATE-ES-QUEUE";

    private static final String UPDATE_DB_QUEUE = "UPDATE-DB-QUEUE";

    //更新数据库队列
    @Bean
    public Queue updateDbQueue() {
        return new Queue(UPDATE_DB_QUEUE, true);
    }

    //更新ES队列
    @Bean
    public Queue updateEsQueue() {
        return new Queue(UPDATE_ES_QUEUE, true);
    }


    //增加点击量交换机
    @Bean
    public FanoutExchange addVisitExchange() {
        return ExchangeBuilder.fanoutExchange(ADD_BOOK_VISIT_EXCHANGE).durable(true).build();
    }

    //更新搜索引擎队列绑定到增加点击量交换机中
    @Bean
    public Binding updateEsBinding(Queue updateEsQueue, FanoutExchange exchange) {
        return BindingBuilder.bind(updateEsQueue).to(exchange);
    }
    //更新数据库绑定到增加点击量交换机中
    @Bean
    public Binding updateDbBinding(Queue updateDbQueue, FanoutExchange exchange) {
        return BindingBuilder.bind(updateDbQueue).to(exchange);
    }

}
